home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / texinfo / info / m-x.c < prev    next >
C/C++ Source or Header  |  1994-01-28  |  5KB  |  196 lines

  1. /* m-x.c -- Meta-X minibuffer reader. */
  2.  
  3. /* This file is part of GNU Info, a program for reading online documentation
  4.    stored in Info format.
  5.  
  6.    Copyright (C) 1993 Free Software Foundation, Inc.
  7.  
  8.    This program is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2, or (at your option)
  11.    any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.    Written by Brian Fox (bfox@ai.mit.edu). */
  23.  
  24. #include "info.h"
  25.  
  26. /* **************************************************************** */
  27. /*                                    */
  28. /*               Reading Named Commands                */
  29. /*                                    */
  30. /* **************************************************************** */
  31.  
  32. /* Read the name of an Info function in the echo area and return the
  33.    name.  A return value of NULL indicates that no function name could
  34.    be read. */
  35. char *
  36. read_function_name (prompt, window)
  37.      char *prompt;
  38.      WINDOW *window;
  39. {
  40.   register int i;
  41.   char *line;
  42.   REFERENCE **array = (REFERENCE **)NULL;
  43.   int array_index = 0, array_slots = 0;
  44.  
  45.   /* Make an array of REFERENCE which actually contains the names of
  46.      the functions available in Info. */
  47.   for (i = 0; function_doc_array[i].func; i++)
  48.     {
  49.       REFERENCE *entry;
  50.  
  51.       entry = (REFERENCE *)xmalloc (sizeof (REFERENCE));
  52.       entry->label = savestring (function_doc_array[i].func_name);
  53.       entry->nodename = (char *)NULL;
  54.       entry->filename = (char *)NULL;
  55.  
  56.       add_pointer_to_array
  57.     (entry, array_index, array, array_slots, 200, REFERENCE *);
  58.     }
  59.  
  60.   line = info_read_completing_in_echo_area (window, prompt, array);
  61.  
  62.   info_free_references (array);
  63.  
  64.   if (!echo_area_is_active)
  65.     window_clear_echo_area ();
  66.  
  67.   return (line);
  68. }
  69.  
  70. DECLARE_INFO_COMMAND (describe_command,
  71.    "Read the name of an Info command and describe it")
  72. {
  73.   char *line;
  74.  
  75.   line = read_function_name ("Describe command: ", window);
  76.  
  77.   if (!line)
  78.     {
  79.       info_abort_key (active_window, count, key);
  80.       return;
  81.     }
  82.  
  83.   /* Describe the function named in "LINE". */
  84.   if (*line)
  85.     {
  86.       char *fundoc;
  87.       VFunction *fun;
  88.  
  89.       fun = named_function (line);
  90.  
  91.       if (!fun)
  92.     return;
  93.  
  94.       window_message_in_echo_area ("%s: %s.",
  95.                    line, function_documentation (fun));
  96.     }
  97.   free (line);
  98. }
  99.  
  100. DECLARE_INFO_COMMAND (info_execute_command,
  101.    "Read a command name in the echo area and execute it")
  102. {
  103.   char *line;
  104.  
  105.   /* Ask the completer to read a reference for us. */
  106.   if (info_explicit_arg || count != 1)
  107.     {
  108.       char *prompt;
  109.  
  110.       prompt = (char *)xmalloc (20);
  111.       sprintf (prompt, "%d M-x ", count);
  112.       line = read_function_name (prompt, window);
  113.     }
  114.   else
  115.     line = read_function_name ("M-x ", window);
  116.  
  117.   /* User aborted? */
  118.   if (!line)
  119.     {
  120.       info_abort_key (active_window, count, key);
  121.       return;
  122.     }
  123.  
  124.   /* User accepted "default"?  (There is none.) */
  125.   if (!*line)
  126.     {
  127.       free (line);
  128.       return;
  129.     }
  130.  
  131.   /* User wants to execute a named command.  Do it. */
  132.   {
  133.     VFunction *function;
  134.  
  135.     if ((active_window != the_echo_area) &&
  136.     (strncmp (line, "echo-area-", 10) == 0))
  137.       {
  138.     free (line);
  139.     info_error ("Cannot execute an `echo-area' command here.");
  140.     return;
  141.       }
  142.  
  143.     function = named_function (line);
  144.     free (line);
  145.  
  146.     if (!function)
  147.       return;
  148.  
  149.     (*function) (active_window, count, 0);
  150.   }
  151. }
  152.  
  153. /* Okay, now that we have M-x, let the user set the screen height. */
  154. DECLARE_INFO_COMMAND (set_screen_height,
  155.   "Set the height of the displayed window")
  156. {
  157.   int new_height;
  158.  
  159.   if (info_explicit_arg || count != 1)
  160.     new_height = count;
  161.   else
  162.     {
  163.       char prompt[80];
  164.       char *line;
  165.  
  166.       new_height = screenheight;
  167.  
  168.       sprintf (prompt, "Set screen height to (%d): ", new_height);
  169.  
  170.       line = info_read_in_echo_area (window, prompt);
  171.  
  172.       /* If the user aborted, do that now. */
  173.       if (!line)
  174.     {
  175.       info_abort_key (active_window, count, 0);
  176.       return;
  177.     }
  178.  
  179.       /* Find out what the new height is supposed to be. */
  180.       if (*line)
  181.     new_height = atoi (line);
  182.  
  183.       /* Clear the echo area if it isn't active. */
  184.       if (!echo_area_is_active)
  185.     window_clear_echo_area ();
  186.  
  187.       free (line);
  188.     }
  189.  
  190.   terminal_clear_screen ();
  191.   display_clear_display (the_display);
  192.   screenheight = new_height;
  193.   display_initialize_display (screenwidth, screenheight);
  194.   window_new_screen_size (screenwidth, screenheight);
  195. }
  196.